<template>
  <div class="home">
    <div class="top-nav">
      <div class="content">
        <!-- 首页链接 -->
        <a href="/index">
          <img src="../assets/wyq-image/logo.gif" alt />
        </a>

        <!-- 导航栏 -->
        <ul class="nav clearfix">
          <li class="long">
            <a
              href="javascript:;"
              class="red"
              id="courseList"
              data-toggle="dropdown"
              aria-haspopup="true"
              aria-expanded="false"
            >
              <strong>SAP在线课程</strong>
              <span class="caret"></span>
            </a>

            <!-- 课程子链接 -->
            <ul class="dropdown-menu" aria-labelledby="courseList">
              <li>
                <a href="/spa" @click="apap(1)">FICO S/4HANA PA教材培训课程</a>
              </li>
              <li role="separator" class="divider"></li>
              <li>
                <a href="/spa" @click="apap(2)">ABAP&HANA高级开发课程</a>
              </li>
              <li role="separator" class="divider"></li>
              <li>
                <a href="/spa" @click="apap(3)">BPC10.0全面预算与合并课程</a>
              </li>
              <li role="separator" class="divider"></li>
              <li>
                <a href="/spa" @click="apap(4)">BW on HANA&BO中级顾问课程</a>
              </li>
              <li role="separator" class="divider"></li>
              <li>
                <a href="/spa" @click="apap(5)">SD模块专题解决方案14讲</a>
              </li>
            </ul>
          </li>
          <li>
            <a href="/recruit" class="blue">
              <strong>SAP招聘</strong>
            </a>
          </li>
          <li class="long">
            <a
              href="javascript:;"
              id="ebookList"
              data-toggle="dropdown"
              aria-haspopup="true"
              aria-expanded="false"
            >
              <strong>SAP电子书</strong>
              <span class="caret"></span>
            </a>

            <!-- 电子书子链接 -->
            <ul class="dropdown-menu" aria-labelledby="ebookList">
              <li>
                <a href="/allbooks">全部</a>
              </li>
              <li role="separator" class="divider"></li>
              <li>
                <a href="/finance">财务</a>
              </li>
              <li role="separator" class="divider"></li>
              <li>
                <a href="/logistics">后勤</a>
              </li>
              <li role="separator" class="divider"></li>
              <li>
                <a href="abapbasis">ABAP&Basis</a>
              </li>
              <li role="separator" class="divider"></li>
              <li>
                <a href="/bwbo">BWBO</a>
              </li>
            </ul>
          </li>
          <li>
            <a href="/textbook">
              <strong>PA教材</strong>
            </a>
          </li>
          <li>
            <a href="/video">
              <strong>SAP视频</strong>
            </a>
          </li>
          <li class="long">
            <a href="/pjdata">
              <strong>SAP项目资料</strong>
            </a>
          </li>
          <li>
            <a href="/library">
              <strong>SAP文库</strong>
            </a>
          </li>
        </ul>

        <!-- 登陆&注册 -->
        <div class="btn-box">
          <button type="button" class="btn btn-default btn-sm" @click="Login">登录</button>
          <button type="button" class="btn btn-warning btn-sm" @click="zhucelogin">注册</button>
        </div>
      </div>
    </div>

    <div class="other">
      <router-view></router-view>
    </div>

    <!-- 登录弹出框 -->
    <el-dialog title="登录SPA文库,分享更多SPA知识!" :visible.sync="registeredVisible" width="35%">
      <el-form
        :model="LoginForm"
        :rules="Loginrules"
        ref="LoginruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="LoginForm.email"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="LoginForm.password"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" @click="LoginInfo">登录</el-button>
        <el-button size="small" type="warning" @click="zhucedialogtrue">注册</el-button>
        <el-button size="small" @click="registeredVisible = false">关闭</el-button>
      </span>
    </el-dialog>

    <!-- 注册弹框 -->
    <el-dialog title="提示" :visible.sync="zhuceVisible" width="35%">
      <el-form
        :model="zhuceruleForm"
        :rules="zhucerules"
        ref="zhuceruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="用户名" prop="username">
          <el-input v-model="zhuceruleForm.username"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="zhuceruleForm.email"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="zhuceruleForm.password"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="zhuceVisible = false">取 消</el-button>
        <el-button type="primary" @click="zhuce">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import qs from "qs";
export default {
  data() {
    // 邮箱检验
    let checkEmail = (rule, value, callback) => {
      // rule 校验规则
      // value 用户在input中输入的值
      // callback 回调函数 无论成功还是失败都要调用
      if (!value) return callback(new Error("请输入您的邮箱"));

      // 如果我们输入的邮箱 能通过正则
      /* eslint-disable */

      if (
        /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(
          value
        )
      ) {
        //
        callback();
      } else {
        callback(new Error("您的邮箱格式不正确"));
      }
    };
    return {
      // 弹出框
      registeredVisible: false,
      // 表单数据
      LoginForm: {
        email: "",
        password: ""
      },
      // 验证规则
      Loginrules: {
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 6, max: 18, message: "长度在 6 到 18 个字符", trigger: "blur" }
        ],
        email: [
          { required: true, message: "请输入邮箱", trigger: "blur" },
          { validator: checkEmail, trigger: "blur" }
        ]
      },
      zhuceVisible: false,
      // 注册数据
      zhuceruleForm: {
        username: "",
        email: "",
        password: ""
      },
      // 注册校验
      zhucerules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 6, max: 18, message: "长度在 6 到 18 个字符", trigger: "blur" }
        ],
        email: [
          { required: true, message: "请输入邮箱", trigger: "blur" },
          { validator: checkEmail, trigger: "blur" }
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 6, max: 18, message: "长度在 6 到 18 个字符", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
      apap(ids) {
       localStorage.setItem('id',ids);
    },
    // 登录框
    Login() {
      this.registeredVisible = true;
    },
    // 表单重置
    reset() {
      this.$refs.LoginruleForm.resetFields();
    },
    resets() {
      this.$refs.zhuceruleForm.resetFields();
    },
    // 登录
    LoginInfo() {
      this.$refs.LoginruleForm.validate(async valid => {
        if (!valid) return false;
        // 发起ajax请求
        let { data: res } = await this.$axios.post(
          "/recruit/login",
          qs.stringify(this.LoginForm)
        );
        if (res.code == "400") {
          this.$message.error(res.message);
          this.reset();
        } else {
          this.$message.success(res.message);
          this.reset();
        }
        this.reset();
        this.registeredVisible = false;
      });
    },
    // 注册
    zhuce() {
      this.$refs.zhuceruleForm.validate(async valid => {
        if (!valid) return false;
        // 发起ajax请求
        let { data: res } = await this.$axios.post(
          "/recruit/zhuce",
          qs.stringify(this.zhuceruleForm)
        );
        if (res.code == "400") {
          this.$message.error(res.message);
          this.resets();
        } else {
          this.$message.success(res.message);
          this.resets();
        }
        this.resets();
        this.zhuceVisible = false;
      });
    },
    zhucedialogtrue() {
      this.registeredVisible = false;
      this.zhuceVisible = true;
    },
    zhucelogin() {
      this.zhuceVisible = true;
    }
  }
};
</script>

<style lang='less' scoped>
// .home{
//   // overflow-x:hidden;
//   // overflow-y:hidden;
// }
// ========顶部导航
.top-nav {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  width: 100%;
  height: 50px;
  background-color: #f8f8f8;
  border: 1px solid #e7e7e7;

  img {
    vertical-align: top;
    width: 200px;
    height: 40px;
    padding-top: 5px;
  }
}

.content {
  width: 1140px;
  margin: 0 auto;

  // 登陆&注册
  .btn-box {
    float: right;
    margin: 7px;
    margin-right: 15px;
    box-sizing: border-box;

    button {
      margin-left: 6px;
    }
  }
}

// 中部导航
.nav {
  position: relative;
  top: -2px;
  display: inline-block;
  height: 47px;
  line-height: 50px;
  margin-left: 25px;

  & > li {
    float: left;
    width: 74px;
    height: 100%;
    text-align: center;
  }

  .long {
    width: 104px;
  }

  a {
    color: #777;
    font-size: 14px;
    font-weight: normal;
    padding: 0px;

    &:hover {
      text-decoration: none;
    }
  }

  .red {
    color: #a94442;
  }

  .blue {
    color: #337ab7;
  }
}

// 下拉菜单
.dropdown-menu {
  border-top-right-radius: 0;
  border-top-left-radius: 0;

  li {
    height: 26px;
    line-height: 1.42857143;
  }

  a {
    padding: 3px 20px;
    font-weight: 400;
    color: #333;
  }

  .divider {
    height: 1px;
  }
}

// ========其他子模块
.other {
  margin-top: 50px;
}
</style>